var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e9aec442c42e96c1c551b1160fb8edc8";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();

//获取来源url
var ref = ''; 
if (document.referrer.length > 0) { 
  ref = document.referrer; 
} 
try { 
  if (ref.length == 0 && opener.location.href.length > 0) { 
   ref = opener.location.href; 
  } 
} catch (e) {}

var $_GET = (function() {
  var url = window.document.location.href.toString();
  var u = url.split("?");
  if (typeof(u[1]) == "string") {
    u = u[1].split("&");
    var get = {};
    for (var i in u) {
      var j = u[i].split("=");
      get[j[0]] = j[1];
    }
    return get;
  } else {
    return {};
  }
})();
//JS操作cookies方法!
//这是有设定过期时间的使用示例：
//s20是代表20秒
//h是指小时，如12小时则是：h12
//d是天数，30天则：d30
//暂时只写了这三种
//setCookie("name","hayden","s20″);
function getsec(str) {
	var str1 = str.substring(1, str.length) * 1;
	var str2 = str.substring(0, 1);
	if (str2 == "s") {
	  return str1 * 1000;
	} else if (str2 == "h") {
	  return str1 * 60 * 60 * 1000;
	} else if (str2 == "d") {
	  return str1 * 24 * 60 * 60 * 1000;
	}
}


//写cookies
function setCookie(name, value, time,path,domain,secure) {
	var strsec = getsec(time);
	var exp = new Date();
	exp.setTime(exp.getTime() + strsec * 1);
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+ (path ? '; path=' + path : '/')+ (domain ? '; domain=' + domain : '')+ (secure ? '; secure' : '');
}

//广告注册来源区分
$(document).ready(function() {
	if ($_GET['adv_id'] && !/.49you.com/i.test(ref)) {
		//sorry
		var value = "advid-"+$_GET['adv_id'];
		setCookie( "49yourefer", value, "s1800", "/", ".49you.com");
	}
});

function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) return unescape(arr[2]);
    else return null;
}

function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}